<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<link rel="stylesheet" href="../../PC/css/reset.css">
	<script src="../js/rem.js"></script>
	<style>
		.box{
			min-height: 100vh;
			background-image: url('https://www.bjtqcy.com/images/index_fwfw4.jpg');
			background-repeat: no-repeat;
			background-size: cover;
			overflow: hidden;
		}
		.form-wrap{
			height: 3.5rem;
			margin-top: 3rem;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			line-height: .8rem;
		}
		.form-wrap span{
			display: inline-block;
			width: 1.3rem;
			text-align: right;
			margin-right: 5px;
			color: #fff;
			font-size: 14px;
		}
		.form-wrap input{
			height: .5rem;
			width: 3rem;
			padding-left: 8px;
			border-radius: 4px;
		}
		.zhuce{
			width: 90vw;
			margin: 0 auto;
			border: 1px solid #999;
			border-radius: 6px;
			height: .8rem;
			text-align: center;
			color: #fff;
			line-height: 0.8rem;
			font-size: 16px;
		}
		.toLogin{
			color: #fff;
			text-align: right;
			padding-right: 1rem;
			margin-bottom: 5px;
		}
	</style>
</head>
<body>
	<div class="box">
		<div class="form-wrap">
			<div><span>手机</span><input type="text" class="phone"></div>
			<div><span>密码</span><input type="password" class="pwd"></div>
			<div><span>确认密码</span><input type="password" class="pwds"></div>
		</div>
		<div class="toLogin" onclick="history.go(-1)">已有账号,去登录</div>
		<div class="zhuce" onclick="regster()">
			注册
		</div>
	</div>
	<script src="../../public1/js/sweetalert.js"></script>
	<script src="../../public1/js/pubilc.js"></script>
	<script src="../../public1/js/md5.js"></script>
	<script>
		var phone = document.querySelector('.phone')
		var pwd = document.querySelector('.pwd')
		var pwds = document.querySelector('.pwds')
		var phoneReg =  /^1[34578]\d{9}$/
		var pass = /^(\w){6}$/;
		function regster(){
			if(!phoneReg.test(phone.value)){
				popupMsg('error','手机格式不正确')
				return
			}
			if(!pass.test(pwd.value)){
				popupMsg('error','六位数密码不规范')
				return
			}
			if(pwd.value===pwds.value){
				xhr({
					url:"/user/register",
					methods:'post',
					data:JSON.stringify({
						userPhone:phone.value,
						password:md5(pwd.value),
						rolu:1
					}),
					success:function(res){
						console.log(res);
						swal({
							title:'注册成功,直接登录?',
							buttons: ["取消", "确定"],
						}).then(res=>{
							if(res){
								xhr({
									methods:'post',
									url:'/user/getLogin',
									data:JSON.stringify({
										userPhone:phone.value,
										password:md5(pwd.value),
										rolu:1
									}),
									success:function(res){
										location.replace('./goodsList.html?token='+res.data.token)
									}
								})
							}
						})
					}
				})
			}else{
				popupMsg('error','密码输入不一致')
			}
		}
	</script>
</body>
</html>